package com.zyf.audio.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.zyf.audio.DruidTest;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * Created by hp on 2021/10/18.
 */
public class DruidUtil {
    private static Connection conn ;
    public static Connection getConn() throws Exception{
        //数据源配置
        Properties properties=new Properties();
        //通过当前类的class对象获取资源文件
        InputStream is = DruidTest.class.getResourceAsStream("/druid.properties");
        properties.load(is);
        //返回的是DataSource，不是DruidDataSource
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);

        //获取连接
        conn = dataSource.getConnection();
        return  conn;
    }
}
